package dukeCE.insightTracker.Classes;

import java.util.List;

import dukeCE.insightTracker.R;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class topicListAdapter extends BaseAdapter {

    private final List<topicListItem> items;
    
    public topicListAdapter(final Context context, final int itemResId,
            final List<topicListItem> items)
    {
        this.items = items;
    }

    public int getCount() {
        return this.items.size();
    }

    public topicListItem getItem(int position) {
        return this.items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }
    


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	
    	final topicListItem item = this.items.get(position);
        View itemView = null;
        LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.topic_list_row, null);


        // Set the text of the item
        
        TextView idHiddenTxt = (TextView) itemView.findViewById(R.id.hiddenTopicID);
        TextView topicTxt = (TextView) itemView.findViewById(R.id.topicTxt);
        TextView desTxt =(TextView) itemView.findViewById(R.id.descriptionTxt);
        
        topicTxt.setText(item.getName());
        desTxt.setText(item.getDes());
        idHiddenTxt.setText( Integer.toString(item.getID())); 
        itemView.setTag( Integer.toString(item.getID()));

        // Set the check-icon
        ImageView imgViewChecked = (ImageView) itemView.findViewById(R.id.checked_icon);
        if(item.isChecked())
        	imgViewChecked.setImageResource(R.drawable.star_icon);
        return itemView;

    }
}